<template>
  <el-dialog :title="formtitle" :visible.sync="dialogVisible" @opened="dialogOpen">
    <table-info
      ref="tabledata"
    />
    <el-form-item class="from-bnts">
        <el-button size="small" type="primary" :loading="loading" @click="saveDept">确认</el-button>
        <el-button size="small" @click="close">取消</el-button>
      </el-form-item>
  </el-dialog>
</template>
<script>
  import deptApi from "@/api/system/dept";
  import roleApi from "@/api/system/role";
  import casecauseApi from "@/api/system/casecause";
  import caseCauselawcontentApi from "@/api/system/caseCauselawcontent";
  import lawuserApi from "@/api/system/lawuser";
  import tableInfo from "./info-table";
  import utils from '@/assets/utils/zhzf-util';

  export default {
    name: "deptAddForm",
    components: {tableInfo},
    data() {
      return {
        loading: false,
        dialogVisible: false,
        dataList: [],
        type: '',//当前弹框类型
        formtitle:'好累啊',
        currentrow: ''
      };
    },
    mounted() {
    },
    methods: {
      async initPage(type,detail) {
        this.dialogVisible = true;
        this.type = type;
        this.loadtabledata(detail);
        this.titleResize(type);
      },
      titleResize(type){
        if(type=='1'){
          this.formtitle = '违法行为代码'
        }else if(type=='2'){
          this.formtitle = '违法法规编码'
        }else if(type=='3'){
          this.formtitle = '执法人'
        }else if(type=='4'){
          this.formtitle = '文书'
        }
      },
      loadtabledata(detail) {
        let method = {}, param = {}, cols = [];
        let isNopage = false;
        let formtype = this.type;
        let isSignalTable = true;
        this.dialogOpen();
        switch (this.type) {
          case '1':
            method = casecauseApi.dropList;
            cols = [{title: '违法行为代码', key: 'casecauseNumber', width: 100}, {title: '违法内容', key: 'content',width:650}];
            break;
          case '2':
            method = caseCauselawcontentApi.getlawcontent;//根据id去查法律法规
            param = {casecauseId:detail.casecauseId};
            cols = [{title: '法律法规编码', key: 'code', width: 100}, {title: '违反条例 ', key: 'yjtl'}, {title: '处罚条款 ', key: 'cfbz',width:400}];
            isNopage = true;
            break;
          case '3':
            method = lawuserApi.stafflist;//查执法人员
            cols = [{title: '机构名称  ', key: 'email', width: 150},{title: '执法人员姓名', key: 'username',width:200}, {title: '证件号  ', key: 'orgCode', width: 150}];
            isNopage = false;
            isSignalTable=false;
            break;
        }
        this.$nextTick(() => {
          this.$refs.tabledata.initPage(method, param, cols,isNopage,formtype,isSignalTable);
        })

      },
      //假数据
      async _fetchData(method, param) {
        let res = await method({param, ...this.pagination});
        this.dataList = res.data.rows;
        this.pagination.total = res.data.rows.length;
      },
      handleCurrentChange(currentRow, oldCurrentRow) {
      },
      async dialogOpen() {
      },
      saveDept(){
        this.$nextTick(() => {
          if(this.type=='1'||this.type=='2'){
            this.$emit("submit", this.$refs.tabledata.currentrow);
            this.close()
          }else if(this.type=='3') {
            this.$emit("submit", this.$refs.tabledata.selected);
            this.close()
          }
        })

      },
      close() {
        this.dialogVisible = false;
      }
    }
  };
</script>
